package com.algorithm;

/**
 * 按奇偶排序数组 II
 */
public class SortArrayByParityIi {

    public static int[] sortArrayByParityII(int[] nums) {
        int j=1;
        for (int i = 0; i < nums.length; i=i+2) {
            if (nums[i]%2==1){
                while (nums[j]%2==1){
                    j=j+2;
                }
                nums[i] = (nums[j] + nums[i]) - (nums[j] = nums[i]);
            }
        }
        return nums;
    }

    public static void main(String[] args) {
        int[] nums={4,2,5,7};
        int[] array = sortArrayByParityII(nums);
        System.out.println(array);
    }
}
